/*******************************************************************************
**
** Copyright (c) 2011 - The OWE Team
**
** This file is part of OWE.
**
** OWE is a free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; version
** version 2.1 of the License.
**
** OWE is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with OWE. If not, see <http://www.gnu.org/licenses/>.
**
*******************************************************************************/

#include <iostream>

#include <owe/configurationdocument.h>
#include <owe/platform.h>
#include <owe/preferenceelement.h>
#include <owe/widgetpackage.h>
#include <owe/widgetinterface.h>

OWE_USE_NAMESPACE

int main(int argc, char **argv)
{
    if (argc < 2 || argc > 3) {
        std::cout << "Usage: widgetinterface <widget> [locale]" << std::endl;
        return 1;
    }

    const char *locale = "";
    if (argc == 3)
        locale = argv[2];

    Platform(argc, argv);

    WidgetPackage package(argv[1]);
    if (!package.isValid()) {
        std::cout << "Widget package " << argv[1] << " is invalid." << std::endl;
        return 1;
    }

    ConfigurationDocument configuration(package);
    if (!configuration.isValid()) {
        std::cout << "Widget configuration " << argv[1] << " is invalid." << std::endl;
        return 1;
    }

    WidgetInterface interface(configuration);
    if (!interface.isValid()) {
        std::cout << "Widget interface " << argv[1] << " is invalid." << std::endl;
        return 1;
    }

    // Dumping default locale
    std::cout << "Widget interface (default locale)" << std::endl;
    std::cout << "# author: " << interface.author() << std::endl;
    std::cout << "# author email: " << interface.authorEmail() << std::endl;
    std::cout << "# author href: " << interface.authorHref() << std::endl;
    std::cout << "# description: " << interface.description() << std::endl;
    std::cout << "# id: " << interface.id() << std::endl;
    std::cout << "# name: " << interface.name() << std::endl;
    std::cout << "# short name: " << interface.shortName() << std::endl;
    std::cout << "# version: " << interface.version() << std::endl;
    std::cout << "# width: " << interface.width() << std::endl;
    std::cout << "# height: " << interface.height() << std::endl << std::endl;

    std::cout << "-----------------------------------------------" << std::endl << std::endl;

    // Dumping locale command line argument
    interface.setLocale(locale);

    std::cout << "Widget interface (locale " <<  locale << ")" << std::endl;
    std::cout << "# author: " << interface.author() << std::endl;
    std::cout << "# author email: " << interface.authorEmail() << std::endl;
    std::cout << "# author href: " << interface.authorHref() << std::endl;
    std::cout << "# description: " << interface.description() << std::endl;
    std::cout << "# id: " << interface.id() << std::endl;
    std::cout << "# name: " << interface.name() << std::endl;
    std::cout << "# short name: " << interface.shortName() << std::endl;
    std::cout << "# version: " << interface.version() << std::endl;
    std::cout << "# width: " << interface.width() << std::endl;
    std::cout << "# height: " << interface.height() << std::endl;

    return 0;
}
